package org.noka.nokatabmenu;

import java.io.IOException;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;

import org.nokatag.system.BugInfoWrint;
import org.nokatag.system.Function;
import org.nokatag.tagjava.NokaTag;

public class NTabMenu extends  NokaTag{
	private static final long serialVersionUID = 3654694901274790250L;
	private String id = null;//div id
	private String height = null;//下拉框高度
	private String optab = null;//初始化打开的菜单id
	private  JspWriter jspOut =null;
	private String onstart = null;//在菜单初始化前调用
	private String onend = null;//在菜单初始化之后调用
	
	public int doStartTag()throws JspException{
		try{
			jspOut= pageContext.getOut();
			HttpServletRequest request = (HttpServletRequest) pageContext.getRequest();
			StringBuilder body = new StringBuilder();
			body.append(potjs(request));//js框架
			body.append(ntabMenuJS(request));//select js
			body.append("<div id=\""+id+"_div_autowidth\" style=\"width:100%;height:0px;top:0px;left:0px;overflow:hidden;position: absolute;z-index:9999;background-color: #000000\"></div>");
			body.append("<div id=\""+id+"_div_autoheight\" style=\"width:0px;height:100%;top:0px;left:0px;overflow:hidden;position: absolute;z-index:9999;background-color: #000000\"></div>");
			body.append("<div style=\"clear: both;\"></div>");
			body.append("<div class=\"noka_tab_menu\" id=\""+id+"\" style=\"display: block;\"></div>");
			body.append("<script type=\"text/javascript\">");
			//---------------显示树形菜单---------------------------
			body.append("Event.observe(document, 'dom:loaded', function() {");
			//--------------------------------------------------------------------
			body.append("var sfg"+id+" = {id:'"+id+"',");
			if(null!=optab){
				body.append("optab:'"+optab+"',");
			}
			if(null!=onstart){
				body.append("onstart:function(){"+onstart+"()},");
			}
			if(null!=onend){
				body.append("onend:function(){"+onend+"()},");
			}
			body.append("lang:{left_close:'"+Function.lung(request,"org_nokatag_tab_left_close")+"',other_colse:'"+Function.lung(request,"org_nokatag_tab_other_colse")+"',right_close:'"+Function.lung(request,"org_nokatag_tab_right_close")+"',reload:'"+Function.lung(request,"org_nokatag_tab_reload_button")+"',my_close:'"+Function.lung(request, "org_nokatag_tab_myself_close")+"'},");
			body.append("tabs:[");
			jspOut.write(body.toString());
		}catch(Exception se){
			 BugInfoWrint.Print(se);
		}
		return EVAL_BODY_INCLUDE;
	}
	public int doEndTag() throws JspException {
		try {
			StringBuilder body = new StringBuilder();
			body.append("]};");
			body.append("var nktab"+id+" = new nokatabmenu(sfg"+id+");");
			body.append("nktab"+id+".show();");
			body.append("});");
			body.append("</script>");
			//---------------显示形菜单---------------------------
			pageContext.getOut().write(body.toString());
			} catch (IOException e) {
				e.printStackTrace();
			}
		return EVAL_PAGE;
	}
	public String getId() {
		return id;
	}
	public void setId(String id) {
		this.id = id;
	}
	public String getHeight() {
		return height;
	}
	public void setHeight(String height) {
		this.height = height;
	}
	public String getOptab() {
		return optab;
	}
	public void setOptab(String optab) {
		this.optab = optab;
	}
	public String getOnstart() {
		return onstart;
	}
	public void setOnstart(String onstart) {
		this.onstart = onstart;
	}
	public String getOnend() {
		return onend;
	}
	public void setOnend(String onend) {
		this.onend = onend;
	}
}
